/*-
 * BusinessExceptionMapper.java
 *
 * Date: 2017年2月23日
 * Time: 下午3:50:05
 *
 * 版权所有©2012-2013 rengh
 */

package com.lmx.repoDomain.exception;

import io.katharsis.errorhandling.ErrorData;
import io.katharsis.errorhandling.ErrorResponse;
import io.katharsis.errorhandling.mapper.ExceptionMapperProvider;
import io.katharsis.errorhandling.mapper.JsonApiExceptionMapper;
import io.katharsis.response.HttpStatus;

@ExceptionMapperProvider
public class BusinessExceptionMapper implements JsonApiExceptionMapper<BusinessException> {
  @Override
  public ErrorResponse toErrorResponse(BusinessException exception) {
    return ErrorResponse.builder()
      .setStatus(HttpStatus.CONFLICT_409)
      .setSingleErrorData(ErrorData.builder()
        .setTitle(exception.getTitle())
        .setId(exception.getId())
        .setCode(exception.getCode())
        .build())
      .build();
  }
}